#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define MAX_K 2500
int main() {
    // 读取数据
    int N, K;
    scanf("%d %d", &N, &K);
    vector<string> data[MAX_K + 1];
    string name;
    for(int i = 0, M, t; i < N; i++){
        cin >> name;
        scanf("%d", &M);
        while (M-- > 0) {
            scanf("%d", &t);
            data[t].push_back(name);
        }
    }

    // 输出
    for(int k = 1; k <= K; k++){
        // 输出前按学生名称字典序排序
        sort(data[k].begin(), data[k].end());
        printf("%d %ld\n", k , data[k].size());
        for(auto lt = data[k].cbegin(); lt != data[k].cend(); lt++){
            printf("%s\n", lt->c_str());
        }
    }
    return 0;
}